<?php

namespace app\controller\v1;

use app\model\OutsourcingOrderModel;
use app\validate\OutsourcingOrderValidate;
use think\App;

class OutsourcingOrder extends System
{
    public function __construct(App $app)
    {
        parent::__construct($app);
    }


    public function list()
    {
        $model = new OutsourcingOrderModel();
        $res = $model->list($this->params);
        if ($res === false) {
            return $this->errorJson($model->getError());
        }

        return $this->successJson('ok', $res);
    }


    /**
     * Notes: 分配订单
     * User: chenLei
     * Date: 11/15/25 23:52:23
     * @return \think\response\Json
     */
    public function assignOrder()
    {
        $validate = new OutsourcingOrderValidate();
        if (!$validate->scene('assignOrder')->check($this->params)) {
            return $this->errorJson($validate->getError());
        }

        $model = new OutsourcingOrderModel();
        $res = $model->assignOrder($this->params);
        if ($res === false) {
            return $this->errorJson($model->getError());
        }

        return $this->successJson('物料订单转交给外协成功');
    }

    public function add()
    {
        $validate = new OutsourcingOrderValidate();
        if (!$validate->scene('add')->check($this->params)) {
            return $this->errorJson($validate->getError());
        }

        $model = new OutsourcingOrderModel();
        $res = $model->add($this->params);
        if ($res === false) {
            return $this->errorJson($model->getError());
        }

        return $this->successJson('物料订单转交给采购成功');
    }
}